import Vue from 'vue'
import Vuex from 'vuex'
import VueCookies from 'vue-cookies'
//
import Api from '../api/tableApi'


Vue.use(Vuex)
Vue.use(VueCookies)

export default new Vuex.Store({
  state: {
    sidebar: {
      closed: false
    },
    token: Vue.$cookies.get('csrftoken'),
    username: Vue.$cookies.get('username'),
    // select 的options
    selectOptions: [],
    // curr 
    currSelectOption: ''
  },
  getters: {
    sidebarTodos: state => {
      return state.sidebar.closed
    },
    token: state => {
      console.log(`token is ${state.token}`)
      return state.token
    },
    username: state => {
      console.log(state.username)
      return state.username
    },
    selectOptions: state => state.selectOptions,
    currSelectOption:  state => {
      console.log("----------------",state.currSelectOption)
      return state.currSelectOption
    }
  },
  mutations: {
    changSiderStatus (state) {
      // 变更侧边栏状态
      state.sidebar.closed = !state.sidebar.closed
      console.log(state.sidebar.closed)
    },
    getUserName(state) {
      state.username = Vue.$cookies.get('username')
    },
    // option
    setSelectOption(state, payload) {
      state.selectOptions = payload
      // console.log(state.selectOptions)
    },
    // curroption
    setCurrSelectOption(state, payload) {
      state.currSelectOption = payload
      // console.log(state.currSelectOption)
    }
  },
  actions: {
    async getSetSelectOption($store) {
      let { commit } = $store
      let list = Api.options
      // console.log(list)
      commit("setSelectOption", list)
      commit("setCurrSelectOption", list[0].value)
    }
  },
  modules: {
  }
})
